package edu.calpoly.android.echoes;

import android.content.Context;
import android.text.TextUtils.TruncateAt;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Checkable;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class SaveView extends LinearLayout implements OnClickListener {

	private TextView m_vwSaveText;
	private String m_save;
	private OnSaveChangeListener m_onSaveChangeListener;
	private Button m_vwLoadButton;

	/**
	 * Basic Constructor that takes only takes in an application Context.
	 * 
	 * @param context
	 *            The application Context in which this view is being added. 
	 *            
	 * @param joke
	 * 			  The Joke this view is responsible for displaying.
	 */
	public SaveView(Context context, String save) {
		super(context);
		
		//Initialize Joke Change Listener
		m_onSaveChangeListener = null;
		
		// Inflate the layout and set this JokeView as the root ViewGroup.
		((LayoutInflater)context
		 .getSystemService(Context.LAYOUT_INFLATER_SERVICE))
		 .inflate(R.layout.save_view, this, true);
		
		//m_vwLoadButton = (Button)findViewById(R.id.loadButton);
		//m_vwLoadButton.setOnClickListener(this);
		
		// Initialize View member variables		
		m_vwSaveText= (TextView)findViewById(R.id.saveTextView);
		
		setSave(save);
	}

	/**
	 * Mutator method for changing the Joke object this View displays. This View
	 * will be updated to display the correct contents of the new Joke.
	 * 
	 * @param joke
	 *            The Joke object which this View will display.
	 */
	public void setSave(String save) {
		m_save = save;
		m_vwSaveText.setText(m_save);
	}
	
	public String getSave() {
		return m_save;
	}
	



	public void onClick(View v) {
		Log.e("onClick", "");
		/*v.setPressed(true);
		m_vwSaveText.setEllipsize(null);
		requestLayout();*/
	}


	/**
	 * Mutator method for changing the OnJokeChangeListener object this JokeView
	 * notifies when the state its underlying Joke object changes.
	 * 
	 * It is possible and acceptable for m_onJokeChangeListener to be null, you
	 * should allow for this.
	 * 
	 * @param listener
	 *            The OnJokeChangeListener object that should be notified when
	 *            the underlying Joke changes state.
	 */
	public void setOnSaveChangeListener(OnSaveChangeListener listener) {
		m_onSaveChangeListener = listener;
	}

	/**
	 * This method should always be called after the state of m_joke is changed.
	 * 
	 * It is possible and acceptable for m_onJokeChangeListener to be null, you
	 * should test for this.
	 * 
	 * This method should not be called if setJoke(...) is called, since the
	 * internal state of the Joke object that m_joke references is not be
	 * changed. Rather, m_joke reference is being changed to reference a
	 * different Joke object.
	 */
	protected void notifyOnSaveChangeListener() {
		if(!(m_onSaveChangeListener == null))
			m_onSaveChangeListener.onSaveChanged(this, m_save);
	}

	/**
	 * Interface definition for a callback to be invoked when the underlying
	 * Joke is changed in this JokeView object.
	 * 
	 */
	public static interface OnSaveChangeListener {

		/**
		 * Called when the underlying Joke in a JokeView object changes state.
		 * 
		 * @param view
		 *            The JokeView in which the Joke was changed.
		 * @param joke
		 *            The Joke that was changed.
		 */
		public void onSaveChanged(SaveView view, String save);
	}

}
